package cn.jroid.demo.ui;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import cn.jroid.demo.R;
import cn.jroid.demo.util.AsyncImageLoader2;
import cn.jroid.ui.BaseActivity;

public class ImageDetailActivity extends BaseActivity {
	
	private TextView userView;
	private ImageView imageView;
	private TextView contentView;
	
	private ProgressBar progress;
	
	private AsyncImageLoader2 asyncImageLoader;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.image_detail);
		buildUI();
	}
	
	private void buildUI() {
		userView = (TextView) findViewById(R.id.user);
		imageView = (ImageView) findViewById(R.id.image);
		contentView = (TextView) findViewById(R.id.content);
		progress = (ProgressBar) findViewById(R.id.progress);
		
		asyncImageLoader = new AsyncImageLoader2();
		
		// 获取屏幕宽度
		DisplayMetrics metric = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metric);
        int _width = metric.widthPixels;
        LayoutParams params = imageView.getLayoutParams();
        params.width = _width;
        params.height = _width - 16;
        System.out.println("宽度是："+_width);
        imageView.setLayoutParams(params);
        
//        LayoutParams proParams = progress.getLayoutParams();
//        proParams.width = _width;
//        proParams.height = _width - 16;
//        progress.setLayoutParams(proParams);
        
        String imageUrl = "http://www.ukulelefoshan.com/template/dsvue_cgmvred_v2/skin_img/logo.png";
        imageView.setTag(imageUrl);
        
        //final ImageView imgView = (ImageView) rowView.findViewById(R.id.image);
        
        Drawable cacheImage = asyncImageLoader.loadDrawable(imageUrl,
				new AsyncImageLoader2.ImageCallback() {
					// 请参见实现：如果第一次加载url时下面方法会执行
					public void imageLoaded(Drawable imageDrawable) {
						imageView.setImageDrawable(imageDrawable);
						progress.setVisibility(View.GONE);
					}
		});
        if (cacheImage != null) {
			((ImageView) findViewById(R.id.image)).setImageDrawable(cacheImage);
			progress.setVisibility(View.GONE);
		}
	}
	
}
